package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.StrategyTheme;
import cn.wolfcode.luowowo.query.StrategyThemeQuery;
import cn.wolfcode.luowowo.service.IStrategyThemeService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 攻略主题
 */
@Controller
@RequestMapping("/strategyTheme")
public class StrategyThemeController {

    @Autowired
    private IStrategyThemeService strategyThemeService;
    

    // 区域显示
    // 这里需要的是分页的数据
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyThemeQuery qo){
        Page<StrategyTheme> page = strategyThemeService.query(qo);
        model.addAttribute("page",page);
        return "/strategyTheme/list";
    }


    
    /**
     * 新增和修改
     * 判断对象中是否有Id来确定执行新增还是修改方法
     * @param strategyTheme
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyTheme strategyTheme){
        if (StringUtils.hasLength(strategyTheme.getId())){
            strategyThemeService.update(strategyTheme);
        }else{
            strategyThemeService.save(strategyTheme);
        }
        return JsonResult.success();
    }


    /**
     * 根据传上来的id删除
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        if (StringUtils.hasLength(id)) {
            strategyThemeService.delete(id);
        }
        return JsonResult.success();
    }




}
